<%--
  Created by IntelliJ IDEA.
  User: Adger
  Date: 2020/8/24
  Time: 16:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%-- 引入jquery --%>
    <script src="js/jquery.min-3.5.js"></script>
</head>
<body>
    <script>
        /**
         * json数据格式
         */
        $(function () {
            var user = {
                "id":1,
                "name":"张三"
            };

            $.ajax({
                url:"data/json",//地址
                data:JSON.stringify(user),//把user对象转换为json数据格式
                type:"POST",//请求方式
                contentType:"application/json;charset=UTF-8",//因为有 中文设置编码
                dataType:"JSON",//返回的数据格式
                success:function (data) {
                    alert(data.id + "--" + data.name)
                }
            })
        })
    </script>
</body>
</html>
